package main

import "fmt"

func main() {
	//第一种使用方式
	var a map[string]string
	//在使用map前,需要先make,make的作用就是给map分配数据空间
	a = make(map[string]string, 10)
	a["no1"] = "宋江"
	a["no2"] = "吴用"
	a["no1"] = "武松"
	a["no3"] = "吴用"
	fmt.Println(a)

	//第二种方式
	cities := make(map[string]string)
	cities["no1"] = "北京"
	cities["no2"] = "天津"
	cities["no3"] = "上海"
	fmt.Println(cities)

	//第三种方式
	heroes := map[string]string{
		"hero1": "宋江",
		"hero2": "卢俊义",
		"hero3": "吴用",
	}
	heroes["hero4"] = "林冲"
	fmt.Println("heroes = ", heroes)

	//案例
	/*
		课堂练习:演示一个key-value 的value是map的案例
		比如:我们要存放3个学生信息,每个学生有name和sex信息
		思路: map[string]map[string]string

	*/
	studentsMap := make(map[string]map[string]string)
	studentsMap["stu01"] = make(map[string]string, 3) //这句话不能少!! 因为map中的map,同样需要先make才能使用,不然会报异常
	studentsMap["stu01"]["name"] = "tom"
	studentsMap["stu01"]["sex"] = "男"
	studentsMap["stu01"]["address"] = "北京长安街"

	studentsMap["stu02"] = make(map[string]string, 3) //这句话不能少!!
	studentsMap["stu02"]["name"] = "mary"
	studentsMap["stu02"]["sex"] = "女"
	studentsMap["stu02"]["address"] = "上海黄浦江"

	fmt.Println(studentsMap)
	fmt.Println(studentsMap["stu02"])
	fmt.Println(studentsMap["stu02"]["address"])

}
